<?php namespace App\Services;

use App\Facades\Infra\RecoveryManager;

use Auth;

class RecoveryService{
	public function addRecovery($data){

		$data['customer_id'] = Auth::user()->id;

		$data['photos'] = json_encode($data['photos']);

		return RecoveryManager::createRecovery($data);
	}

	public function getRecoveryByStatus($data){
		$conditions = [
			'status' => $data['status'],
			'customer_id' => Auth::user()->id
		];

		return RecoveryManager::getReoverise($conditions,$first= true)->orderBy('created_at','desc')->get();
	}

	public function updateRecovery($data){
		$id = $data['id'];

		$data['photos'] = json_encode($data['photos']);

		return RecoveryManager::updateRecovery($id,$data);
	}

	public function getRecoveryTypes(){
		return RecoveryManager::getRecoveryTypes($conditions = null,$first = true)->orderBy('created_at','desc')->get();
	}

	public function getRecoveries(){
		$conditions = [
			'customer_id' => Auth::user()->id
		];

		return RecoveryManager::getReoverise($conditions,$first= true)->orderBy('created_at','desc')->get();
	}
}